from django.contrib import admin
from jrcmodel.models import TimeLevel, CST, Market, Asset, Portfolio,\
    JrcParameter, JrcSystem, ProfitLossesValues, StockExchange
from django.http import HttpResponseRedirect
from django.contrib.admin.options import ModelAdmin

class StockExchangeAdmin(admin.ModelAdmin):
    list_display = ("pk", "status_name", "name", "label")

class CSTInline(admin.StackedInline):
    model = CST
    extra = 1

class CSTAdmin(admin.ModelAdmin):
#    list_display = ("status_id", "name", "market_direction_1", "market_direction_2", "timelevel_m", "created_at")
    list_display = ("status_id", "name", "market_direction_1", "market_direction_2", "created_at")
#    actions = ["import_csv_file"]
#
#    def import_csv_file(self, request, queryset):
#        selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
#        print selected[0]
#        return HttpResponseRedirect("/ximport/%s/parse/" % selected[0])

class MarketsInline(admin.TabularInline):
    fields = ( "status_id", "name", "stock_exchange_id", "currency_code", "points", "point_price"  )
    model = Market
    extra = 0

class AssetAdmin(admin.ModelAdmin):
    list_display = ("name", "status_name")
    inlines = [MarketsInline]

class PortfolioAdmin(admin.ModelAdmin):
    list_display = ("status_id", "name", "cst_qnt", "weighting")

class JrcSystemAdmin(admin.ModelAdmin):
    list_display = ("status_id", "name", "priority", "created_at")

class JrcParameterAdmin(admin.ModelAdmin):
    list_display = ("status_id", "system_id", "market_id", "direction_id", "cash_or_future")

class MarketAdmin(admin.ModelAdmin):
    list_display = ("status_id", "asset", "name", "priority", "get_price_of_points")

class ProfitLossesAdmin(admin.ModelAdmin):
    list_display = ("status_id", "market", "get_asset_class", "year", "month", "value")
    ordering = ["-market__asset"]

admin.site.register(Portfolio, PortfolioAdmin)
admin.site.register(TimeLevel)
admin.site.register(CST, CSTAdmin)
admin.site.register(Asset, AssetAdmin)
admin.site.register(Market, MarketAdmin)
admin.site.register(JrcParameter, JrcParameterAdmin)
admin.site.register(JrcSystem, JrcSystemAdmin)
admin.site.register(ProfitLossesValues, ProfitLossesAdmin)
admin.site.register(StockExchange, StockExchangeAdmin)

